
package com.mbbmap.app.home;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Properties;

import com.mbbmap.app.manager.SystemLogManager;
import com.mbbmap.util.Constants;
import com.mbbmap.util.DateUtil;
import com.mbbmap.util.EnhancedException;


/**
 * @author Lue
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ParamHome {

    //  System Config setting in DB
    // NOTE: When add new param, ADD in saveParams() as well
    public static final String PARAM_TYPE_SEC = "SEC";
    public static final String PARAM_TYPE_TECH = "TECH";
  //16 constants
  public static final String TECH_PASSWORD_RESET_FLAG ="pwdResetFlag";
  public static final String TECH_PARAM_PASSWORD_REG_EXPR ="userPwdRegex";
  public static final String TECH_PARAM_TOTAL_PASSWORD_HIST ="T_PWD_HIST";
  public static final String TECH_PARAM_PASSWORD_RESET_FLAG ="pwdResetFlag";
  public static final String SEC_ALLOW_SAME_USER_ID_PW ="allowSameUserIdPwd";
  public static final String SEC_PW_EXPIRY_DAY ="pwdExpiryDays";
  public static final String SEC_BAD_PW_ATTEMPTS ="badPwdAttempts";
  public static final String SEC_CHG_PW_FIR_LOGON ="changePwdFirstLogon";
  public static final String SEC_UID_MIN_LEN ="userLoginIdMinLen";
  public static final String SEC_UID_MAX_LEN ="userLoginIdMaxLen";
  public static final String SEC_UserPwdMinLen ="userPwdMinLen";
  public static final String SEC_UserPwdMaxLen ="userPwdMaxLen";
  public static final String SEC_LOGOUT_TIME ="improperLogoutTimeOutMin";
  public static final String SEC_USER_DOR_DAYS ="userDormantDays";
  public static final String SEC_MAX_WEB_CON ="maxwebconn";
  public static final String SEC_USER_INACTIVE ="userInactiveDaysReport";
  public static final String SEC_DAY_LIMIT ="dailytxnlimit";
  public static final String TECH_MQ_TIMEOUT ="mqtimeout";
  public static final String TECH_MQ_LOOP ="mqloop";
  public static final String SEC_LOGIN_ID_MAX_LEN = "userLoginIdMaxLen";

  public static final String SEC_DISABLE_TIMESTAMP_FR ="disabletimestampfr";
  public static final String SEC_DISABLE_TIMESTAMP_TO ="disabletimestampto";

  
	private static ParamHome instance = null;

	/**
	 * Returns the single instance, creating one if it's the
	 * first time this method is called.
	 *
	 * @return PropertyHome. The single instance.
	 */
	public static ParamHome getInstance() {
		//thread-safe implementation
		if (instance == null) {
			synchronized (ParamHome.class) {
				if (instance == null) {
					instance = new ParamHome();
				}
			}
		}
		return instance;
	}

	private ParamHome() {
		super();
	}

	public Properties getParamValues (String merchantName, String paramType) {
	    Properties paramProp = new Properties();

        String querySql = null;
        Connection connection=null;
        PreparedStatement pstmtQuery = null;
        SystemLogManager sysLogMgr = SystemLogManager.getInstance();;
        DBAccessHome dba = DBAccessHome.getInstance();

        try {
            connection = dba.getDBConnection();

            if (merchantName == null || paramType == null || paramType.trim().equals("") || merchantName.trim().equals("") ) {
                throw new Exception("merchant name or parameter type is null or blank");
            }

            if (connection == null) {
                System.err.println("ParamHome.getParamValues(String, String): DB Connection is null");
                throw new Exception ("DB Connection is null");
            }
            querySql = "select param_name, param_value from  " + Constants.DB_TBL_PARAMETERS + " where mer_name=? and param_type=?  ";
            pstmtQuery =  connection.prepareStatement(querySql);
            pstmtQuery.setString(1, merchantName);
            pstmtQuery.setString(2, paramType);

            // execute query
            ResultSet rs = pstmtQuery.executeQuery();
            while (rs.next()) {
                paramProp.setProperty(rs.getString(1), rs.getString(2));
            }
            rs.close();

        } catch (java.sql.SQLException sqle) {
            sysLogMgr.logMsg("ParamHome.getParamValues(String, String): Error in SQL execution : " + querySql + "\n" + sqle);
            sqle.printStackTrace();
        } catch (Exception ex) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String, String) : \n" + ex);
            ex.printStackTrace();
        } catch (Throwable t) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String, String) : \n" + t);
            t.printStackTrace();
        } finally {
			if (pstmtQuery != null) {
				try {
				    pstmtQuery.close();
				} catch (SQLException e1) {
		            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String, String) : Error closing pstmtQuery\n" + e1);
		            e1.printStackTrace();
				}
			}
            dba.freeDBConnection (connection);
		}

	    return paramProp;
	}

	public Properties getParamValues (String merchantName) {
	    Properties paramProp = new Properties();

        String querySql = null;
        Connection connection=null;
        PreparedStatement pstmtQuery = null;
        SystemLogManager sysLogMgr = SystemLogManager.getInstance();;
        DBAccessHome dba = DBAccessHome.getInstance();

        try {
            connection = dba.getDBConnection();

            if (merchantName == null ||  merchantName.trim().equals("") ) {
                throw new Exception("merchant name or parameter type is null or blank");
            }

            if (connection == null) {
                System.err.println("ParamHome.getParamValues(String): DB Connection is null");
                throw new Exception ("DB Connection is null");
            }
            querySql = "select param_name, param_value from  " + Constants.DB_TBL_PARAMETERS + " where mer_name=? ";
            pstmtQuery =  connection.prepareStatement(querySql);
            pstmtQuery.setString(1, merchantName);

            // execute query
            ResultSet rs = pstmtQuery.executeQuery();
            while (rs.next()) {
                paramProp.setProperty(rs.getString(1), rs.getString(2));
            }
            rs.close();

        } catch (java.sql.SQLException sqle) {
            sysLogMgr.logMsg("ParamHome.getParamValues(String): Error in SQL execution : " + querySql + "\n" + sqle);
            sqle.printStackTrace();
        } catch (Exception ex) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String) : \n" + ex);
            ex.printStackTrace();
        } catch (Throwable t) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String) : \n" + t);
            t.printStackTrace();
        } finally {
			if (pstmtQuery != null) {
				try {
				    pstmtQuery.close();
				} catch (SQLException e1) {
		            sysLogMgr.logMsg("Error in ParamHome.getParamValues(String) : Error closing pstmtQuery\n" + e1);
		            e1.printStackTrace();
				}
			}
            dba.freeDBConnection (connection);
		}

	    return paramProp;
	}

	public String getParamValue (String merchantName, String paramType, String paramName) {

	    String querySql = null;
        String paramValue=null;
        Connection connection=null;
        PreparedStatement pstmtQuery = null;
        SystemLogManager sysLogMgr = SystemLogManager.getInstance();;
        DBAccessHome dba = DBAccessHome.getInstance();

        try {
            connection = dba.getDBConnection();

            if (paramType == null || paramName == null || merchantName == null ||
                    paramType.trim().equals("") || paramName.trim().equals("") || merchantName.trim().equals("")) {
                throw new Exception("merchant name, parameter type or parameter name is null or blank");
            }

            if (connection == null) {
                System.err.println("ParamHome.getParamValue(): DB Connection is null");
                throw new Exception ("DB Connection is null");
            }
            querySql = "select distinct param_value from  " + Constants.DB_TBL_PARAMETERS + " where mer_name = ? and param_type=?  and param_name=?";
            pstmtQuery =  connection.prepareStatement(querySql);
            pstmtQuery.setString(1, merchantName);
            pstmtQuery.setString(2, paramType);
            pstmtQuery.setString(3, paramName);

            // execute query
            ResultSet rs = pstmtQuery.executeQuery();
            if (rs.next()) {
                paramValue = rs.getString(1);
            }
            rs.close();

        } catch (java.sql.SQLException sqle) {
            sysLogMgr.logMsg("ParamHome.getParamValue(): Error in SQL execution : " + querySql + "\n" + sqle);
            sqle.printStackTrace();
        } catch (Exception ex) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValue() : \n" + ex);
            ex.printStackTrace();
        } catch (Throwable t) {
            sysLogMgr.logMsg("Error in ParamHome.getParamValue() : \n" + t);
            t.printStackTrace();
        } finally {
			if (pstmtQuery != null) {
				try {
				    pstmtQuery.close();
				} catch (SQLException e1) {
		            sysLogMgr.logMsg("Error in ParamHome.getParamValue() : Error closing pstmtQuery\n" + e1);
		            e1.printStackTrace();
				}
			}
            dba.freeDBConnection (connection);
		}

        return paramValue;
	}

	/**
	 * added by ronnie for insert Parameter into database(20090122)
	 * updated by Lue 20090916
	 *
	 */
	public boolean saveParam(String merchantName, String loginId, String paramType, String paramKey, String paramValue)
	{
        boolean success = true;
	    Connection connection=null;
        SystemLogManager sysLogMgr = SystemLogManager.getInstance();;
        DBAccessHome dba = DBAccessHome.getInstance();

        StringBuffer querySql = new StringBuffer("");
        StringBuffer insertSql= new StringBuffer("");
        StringBuffer updateSql = new StringBuffer("");

        PreparedStatement pstmtInsert = null;
        PreparedStatement pstmtQuery = null;
        PreparedStatement pstmtUpdate = null;

        ResultSet rs = null;
        int noUpdated = 0;

        try {

            connection = dba.getDBConnection();

            if (loginId == null || merchantName ==null || paramType == null || paramKey == null || paramValue == null
                    || loginId.trim().equals("") || merchantName.trim().equals("") || paramType.trim().equals("") || paramKey.trim().equals("")
                    || paramValue.trim().equals("")) {
                throw new Exception(
                        "Merchant Name, User logon ID, Parameter Type, Key or Value is null or blank");
            }

            if (connection == null) {
                System.err.println("ParamHome.saveParam(): DB Connection is null");
                throw new Exception("DB Connection is null");
            }

            boolean found = false;
            querySql.append("select PARAM_VALUE from ").append(Constants.DB_TBL_PARAMETERS);
            querySql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? ");

            pstmtQuery = connection.prepareStatement(querySql.toString());
            pstmtQuery.setString(1, paramType);
            pstmtQuery.setString(2, paramKey);

            rs = pstmtQuery.executeQuery();

            if (rs.next()) {
                found = true;
            }

            rs.close();
            pstmtQuery.close();

            java.util.Date now = new java.util.Date();

            if (!found) {

                insertSql.append("INSERT INTO ").append(Constants.DB_TBL_PARAMETERS);
                insertSql.append(" (MER_NAME, PARAM_TYPE, PARAM_CODE, PARAM_NAME, PARAM_VALUE, PARAM_1, PARAM_2, PARAM_3, PARAM_4, CREATED_BY, CREATED_DATE) ");
                insertSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ");

                pstmtInsert = connection.prepareStatement(insertSql.toString());
                pstmtInsert.setString(1, merchantName);
                pstmtInsert.setString(2, paramType);
                pstmtInsert.setString(3, "");
                pstmtInsert.setString(4, paramKey);
                pstmtInsert.setString(5, paramValue);
                pstmtInsert.setString(6, "");
                pstmtInsert.setString(7, "");
                pstmtInsert.setString(8, "");
                pstmtInsert.setString(9, "");
                pstmtInsert.setString(10, loginId);
                pstmtInsert.setDate(11, new java.sql.Date(now.getTime()));

                noUpdated = pstmtInsert.executeUpdate();
                pstmtInsert.close();
            } else {
                updateSql.append("Update ").append(Constants.DB_TBL_PARAMETERS);
                updateSql.append(" SET PARAM_VALUE = ?,  CREATED_BY = ?, CREATED_DATE = ? ");
                updateSql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? and MER_NAME = ? ");

                pstmtUpdate = connection.prepareStatement(updateSql.toString());
                pstmtUpdate.setString(1, paramValue);
                pstmtUpdate.setString(2, loginId);
                pstmtUpdate.setDate(3, new java.sql.Date(now.getTime()));
                pstmtUpdate.setString(4, paramType);
                pstmtUpdate.setString(5, paramKey);
                pstmtUpdate.setString(6, merchantName);

                noUpdated = pstmtUpdate.executeUpdate();
                pstmtUpdate.close();
            }

            if (noUpdated < 1) {
                success = false;
            }


        } catch (SQLException sqle) {
            success = false;
            EnhancedException ex = new EnhancedException(sqle.toString());
            ex.setExceptionLocation("ParamHome.saveParam() ");
            ex.setExtraMessage("SQLException Encountered");
            sysLogMgr.logError(ex);
        } catch (Exception e) {
            success = false;
            EnhancedException ex = new EnhancedException(e.toString());
            ex.setExceptionLocation("ParamHome.saveParam() ");
            ex.setExtraMessage("Exception Encountered");
            sysLogMgr.logError(ex);
        } catch (Throwable t) {
            success = false;
            EnhancedException ex = new EnhancedException(t.toString());
            ex.setExceptionLocation("ParamHome.saveParam() ");
            ex.setExtraMessage("Throwable Encountered");
            sysLogMgr.logError(ex);
        } finally {

            if (rs !=null) {
                try {
                    rs.close();
                } catch (SQLException e1){
                }
            }

            if (pstmtQuery != null) {
                try {
                    pstmtQuery.close();
                } catch (SQLException e1) {
                }
            }

            if (pstmtInsert != null) {
                try {
                    pstmtInsert.close();
                } catch (SQLException e1) {
                }
            }

            if (pstmtUpdate != null) {
                try {
                    pstmtUpdate.close();
                } catch (SQLException e1) {
                }
            }

            dba.freeDBConnection (connection);
        }

        return success;
    }

	/**
	 * Save all parameters in the properties
	 * added by ronnie for insert Parameter into database(20090122)
	 * updated by Lue 20090916
	 *
	 */
	public boolean saveParams (String merchantName, String loginId, Properties prop)
	{
        boolean success = true;
	    Connection connection=null;
        SystemLogManager sysLogMgr = SystemLogManager.getInstance();;
        DBAccessHome dba = DBAccessHome.getInstance();

        StringBuffer querySql = new StringBuffer("");
        StringBuffer insertSql= new StringBuffer("");
        StringBuffer updateSql = new StringBuffer("");

        PreparedStatement pstmtInsert = null;
        PreparedStatement pstmtQuery = null;
        PreparedStatement pstmtUpdate = null;
		PreparedStatement pstmtInsertMQ = null;

        ResultSet rs = null;
        int noUpdated = 0;
        String paramName="", paramValue="", paramType="";

        try {

            connection = dba.getDBConnection();

            if (loginId == null || merchantName ==null || prop == null
                    || loginId.trim().equals("") || merchantName.trim().equals("") ) {
                throw new Exception(
                        "Merchant Name, User logon ID or properties is null or blank");
            }

            if (connection == null) {
                System.err.println("ParamHome.saveParams(): DB Connection is null");
                throw new Exception("DB Connection is null");
            }

            Enumeration en = prop.propertyNames();
            java.util.Date now = new java.util.Date();

            // loop thru the properties
            while (en.hasMoreElements()) {
                paramName = (String) en.nextElement();

                if (paramName.equals(SEC_ALLOW_SAME_USER_ID_PW) || paramName.equals(SEC_PW_EXPIRY_DAY)|| paramName.equals(SEC_BAD_PW_ATTEMPTS)||
                        paramName.equals(SEC_CHG_PW_FIR_LOGON)|| paramName.equals(SEC_UID_MIN_LEN)|| paramName.equals(SEC_UID_MAX_LEN)||
                        paramName.equals(SEC_UserPwdMinLen)|| paramName.equals(SEC_UserPwdMaxLen)|| paramName.equals(SEC_LOGOUT_TIME) ||
                        paramName.equals(SEC_USER_DOR_DAYS)|| paramName.equals(SEC_USER_INACTIVE)|| paramName.equals(SEC_MAX_WEB_CON) ||paramName.equals(SEC_DAY_LIMIT)
                        ){
                    paramType = PARAM_TYPE_SEC;
                    paramValue = prop.getProperty(paramName);
                    System.out.println("ParamName=" + paramName +", paramValue=" + paramValue);
                } else if ( paramName.equals(TECH_PARAM_PASSWORD_REG_EXPR) || paramName.equals(TECH_PARAM_TOTAL_PASSWORD_HIST) || paramName.equals(TECH_PASSWORD_RESET_FLAG) || 
					paramName.equals(TECH_MQ_TIMEOUT)|| paramName.equals(TECH_MQ_LOOP) ) {
                    paramType = PARAM_TYPE_TECH;
                    paramValue = prop.getProperty(paramName);
                    System.out.println("ParamName=" + paramName +", paramValue=" + paramValue);
                } else {
                    //skip the unknown param so that it is not inserted into the table
                    System.out.println("SKIP ParamName=" + paramName);
                    continue;
                }

	            boolean found = false;
	            querySql.delete(0, querySql.length());
	            querySql.append("select PARAM_VALUE from ").append(Constants.DB_TBL_PARAMETERS);
	            querySql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? ");

	            pstmtQuery = connection.prepareStatement(querySql.toString());
	            pstmtQuery.setString(1, paramType);
	            pstmtQuery.setString(2, paramName);
	            System.out.println("QUERY="+querySql.toString());
	            System.out.println("paramType="+paramType+", paramName="+paramName);

	            rs = pstmtQuery.executeQuery();

	            if (rs.next()) {
	                found = true;
	            }

	            rs.close();
	            pstmtQuery.close();

	            if (!found) {

	                insertSql.delete(0, insertSql.length());
	                insertSql.append("INSERT INTO ").append(Constants.DB_TBL_PARAMETERS);
	                insertSql.append(" (MER_NAME, PARAM_TYPE, PARAM_CODE, PARAM_NAME, PARAM_VALUE, PARAM_1, PARAM_2, PARAM_3, PARAM_4, CREATED_BY, CREATED_DATE) ");
	                insertSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ");

	                pstmtInsert = connection.prepareStatement(insertSql.toString());
	                pstmtInsert.setString(1, merchantName);
	                pstmtInsert.setString(2, paramType);
	                pstmtInsert.setString(3, "");
	                pstmtInsert.setString(4, paramName);
	                pstmtInsert.setString(5, paramValue);
	                pstmtInsert.setString(6, "");
	                pstmtInsert.setString(7, "");
	                pstmtInsert.setString(8, "");
	                pstmtInsert.setString(9, "");
	                pstmtInsert.setString(10, loginId);
	                pstmtInsert.setDate(11, new java.sql.Date(now.getTime()));

	                System.out.println("...INSERT");
	                noUpdated = pstmtInsert.executeUpdate();
	                System.out.println("...INSERT OK");
	                pstmtInsert.close();

	//send MQ to host for transaction limit, create

							if(paramName.equals("dailytxnlimit")){


								java.util.Date datenow = new java.util.Date();
								String stringNow = DateUtil.formatDateTimeDash(datenow);

								String stringDate =  stringNow.substring(0,4)+ stringNow.substring(5,7)+stringNow.substring(8,10);
								String stringTime = stringNow.substring(11,13)+stringNow.substring(14,16)+stringNow.substring(17,19);

								String header ="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
								String messageCode = "ALM";
								String translimitValue = formatMMENumber(paramValue,15);

/* Remark for Mandiri
								String insertSqlMQ ="INSERT INTO TBLMQMESSAGE (ACTIONDATE, ACTIONTIME, HOST_FLAG, MESSAGE, LOG_PATH, FILE_COUNT, LOG_FILE_APPEND, LOG_FILE_PATTERN, QUEUE_NAME) VALUES (?,?,?,?,?,?,?,?,?)";

								pstmtInsertMQ = connection.prepareStatement(insertSqlMQ.toString());

								pstmtInsertMQ.setString(1, stringDate);
								pstmtInsertMQ.setString(2, stringTime);
								pstmtInsertMQ.setString(3, "0");
								pstmtInsertMQ.setString(4, header + messageCode + translimitValue);
								pstmtInsertMQ.setString(5, Constants.PARAMETER_LOG_PATH);
								pstmtInsertMQ.setString(6, Constants.PARAMETER_FILE_COUNT);
								pstmtInsertMQ.setString(7, Constants.PARAMETER_LOG_FILE_APPEND);
								pstmtInsertMQ.setString(8, Constants.PARAMETER_LOG_FILE_PATTERN);
								pstmtInsertMQ.setString(9, Constants.PARAMETER_QUEUE_NAME);

*/
								System.out.println("**********************************************************************");


								System.out.println(paramValue);

								//pstmtInsertMQ.executeUpdate();

							}



	//end send MQ to host for transaction limit, create

	            } else {
	                updateSql.delete(0, updateSql.length());
	                updateSql.append("Update ").append(Constants.DB_TBL_PARAMETERS);
	                updateSql.append(" SET PARAM_VALUE = ?,  CREATED_BY = ?, CREATED_DATE = ? ");
	                updateSql.append(" Where PARAM_TYPE = ? and PARAM_NAME = ? and MER_NAME = ? ");

	                pstmtUpdate = connection.prepareStatement(updateSql.toString());
	                pstmtUpdate.setString(1, paramValue);
	                pstmtUpdate.setString(2, loginId);
	                pstmtUpdate.setDate(3, new java.sql.Date(now.getTime()));
	                pstmtUpdate.setString(4, paramType);
	                pstmtUpdate.setString(5, paramName);
	                pstmtUpdate.setString(6, merchantName);

	                System.out.println("...UPDATE");
	                noUpdated = pstmtUpdate.executeUpdate();
	                pstmtUpdate.close();
	                System.out.println("...UPDATE OK");


	//send MQ to host for transaction limit, update


							if(paramName.equals("dailytxnlimit")){


								java.util.Date datenow = new java.util.Date();
								String stringNow = DateUtil.formatDateTimeDash(datenow);

								String stringDate =  stringNow.substring(0,4)+ stringNow.substring(5,7)+stringNow.substring(8,10);
								String stringTime = stringNow.substring(11,13)+stringNow.substring(14,16)+stringNow.substring(17,19);

								String header ="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
								String messageCode = "ULM";
								String translimitValue = formatMMENumber(paramValue,15);


								String insertSqlMQ ="INSERT INTO TBLMQMESSAGE (ACTIONDATE, ACTIONTIME, HOST_FLAG, MESSAGE, LOG_PATH, FILE_COUNT, LOG_FILE_APPEND, LOG_FILE_PATTERN, QUEUE_NAME) VALUES (?,?,?,?,?,?,?,?,?)";
/* 20130225-Remark for Mandiri
								pstmtInsertMQ = connection.prepareStatement(insertSqlMQ.toString());

								pstmtInsertMQ.setString(1, stringDate);
								pstmtInsertMQ.setString(2, stringTime);
								pstmtInsertMQ.setString(3, "0");
								pstmtInsertMQ.setString(4, header + messageCode + translimitValue);
								pstmtInsertMQ.setString(5, Constants.PARAMETER_LOG_PATH);
								pstmtInsertMQ.setString(6, Constants.PARAMETER_FILE_COUNT);
								pstmtInsertMQ.setString(7, Constants.PARAMETER_LOG_FILE_APPEND);
								pstmtInsertMQ.setString(8, Constants.PARAMETER_LOG_FILE_PATTERN);
								pstmtInsertMQ.setString(9, Constants.PARAMETER_QUEUE_NAME);
								pstmtInsertMQ.executeUpdate();
*/
							}


	////end send MQ to host for transaction limit, update
	            }

	            if (noUpdated < 1) {
	                success = false;
	                break;
	            }

            } //end while loop

        } catch (SQLException sqle) {
            success = false;
            EnhancedException ex = new EnhancedException(sqle.toString());
            ex.setExceptionLocation("ParamHome.saveParams() ");
            ex.setExtraMessage("SQLException Encountered");
            sysLogMgr.logError(ex);
            sqle.printStackTrace();
        } catch (Exception e) {
            success = false;
            EnhancedException ex = new EnhancedException(e.toString());
            ex.setExceptionLocation("ParamHome.saveParams() ");
            ex.setExtraMessage("Exception Encountered");
            sysLogMgr.logError(ex);
            e.printStackTrace();
        } catch (Throwable t) {
            success = false;
            EnhancedException ex = new EnhancedException(t.toString());
            ex.setExceptionLocation("ParamHome.saveParams() ");
            ex.setExtraMessage("Throwable Encountered");
            sysLogMgr.logError(ex);
            t.printStackTrace();
        } finally {

            if (rs !=null) {
                try {
                    rs.close();
                } catch (SQLException e1){
                }
            }

            if (pstmtQuery != null) {
                try {
                    pstmtQuery.close();
                } catch (SQLException e1) {
                }
            }

            if (pstmtInsert != null) {
                try {
                    pstmtInsert.close();
                } catch (SQLException e1) {
                }
            }

            if (pstmtUpdate != null) {
                try {
                    pstmtUpdate.close();
                } catch (SQLException e1) {
                }
            }

            dba.freeDBConnection (connection);
        }

        return success;
    }


    private String formatMMENumber(String param,int length){
		double myValue = 0;
		int myInt= 0;
		if(param==null){
			param="";
		}
		if(!param.equals("")){
			myValue = Double.parseDouble(param);
		}
		myValue = Math.round(myValue*100);
		myInt = (int)myValue;
		param = Integer.toString(myInt);

		int paramLength = param.length();

		if(length>paramLength){
			for(int i=0;i<length-paramLength;i++){
				param = "0"+param;
			}
		}
		return param;

	}


}
